from django.contrib import admin

# Register your models here.
from myApp.models import Grade,Student,Article

class StudentInLine(admin.TabularInline):
    model = Student
    extra = 3

# class GradeAdmin(admin.ModelAdmin):
#     inlines = [StudentInLine]
#     list_display = ["id","name","boyNum","girlNum","isDelete"]
# admin.site.register(Grade,GradeAdmin)
# 使用装饰器进行注册
@admin.register(Grade)
class GradeAdmin(admin.ModelAdmin):
    inlines = [StudentInLine]
    list_display = ["id","name","boyNum","girlNum","isDelete"]


class StudentAdmin(admin.ModelAdmin):
    actions_on_top = True
    actions_on_bottom = False
    def sex(self):  # 修改性别显示
        if self.sex:
            return "男"
        else:
            return "女"
    sex.short_description = "性别"  # 改变列名的名称
    def content(self):
        return self.content
    # 列表属性
    # list_display =  ["id","name","age","sex","content","grade","isDelete"]
    list_display =  ["id","name","age", sex, content,"grade","isDelete"]
    list_filter = ["grade"]
    search_fields = ["content","name"]
    list_per_page = 6
    # fields =  ["name","age","sex","grade","content","isDelete"]
    fieldsets = [
        ("基本信息",{"fields":["name","age","sex"]}),
        ("更多信息",{"fields":["grade","content","isDelete"]})]
admin.site.register(Student, StudentAdmin)


admin.site.register(Article)